package com.example.controller;



import com.example.utils.AjaxResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.example.domain.Reservation;
import com.example.service.ReservationService;

import java.util.HashMap;
import java.util.List;

import static com.example.utils.AjaxResult.successData;

@RestController
@RequestMapping("/root")
public class ReservationController {

    @Autowired
    private ReservationService reservationService;

    /** 预约管理 */
    @RequestMapping("/reservation")
    public AjaxResult reservation(@RequestParam(defaultValue = "1", value = "page") Integer pageNum,
                                  @RequestParam(defaultValue = "10", value = "limit") Integer pageSize,
                                  @RequestParam(defaultValue = "" , value = "reservation") String usr
    ){
        HashMap<String, Object> map = new HashMap<>();
        PageHelper.startPage(pageNum,pageSize);
        if (usr == null || usr.equals("")) {
            System.out.println("tests1");
            map.put("usr","");
            List<Reservation> reservations = reservationService.listAll(1);
            System.out.println(reservations.toString());
            PageInfo<Reservation> page = new PageInfo<>(reservations);
            return successData(page.getTotal(), reservations);
        }
        System.out.println("tests22");
        map.put("usr",usr);
        List<Reservation> reservations = reservationService.listAll(1);
        PageInfo<Reservation> page = new PageInfo<>(reservations);
        return successData(page.getTotal(), reservations);
    }
}
